package cn.edu.sdjzu.xg2121.controller;



import cn.edu.sdjzu.xg2121.exception.BysjException;
import cn.edu.sdjzu.xg2121.service.UniversityService;
import com.alibaba.fastjson2.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;


@WebServlet("/universityDelete.ctl")
public class UniversityDeleteCtl extends HttpServlet {
    protected void doDelete(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        JSONObject message_jsonObj=new JSONObject();
        response.setContentType("application/json;charset=UTF-8");
        try{
            String id_str = request.getParameter("id");
            int id = Integer.parseInt(id_str);
            UniversityService.getInstance().delete(id);
            message_jsonObj.put("message", "删除成功");
        }
        catch(BysjException e){
            message_jsonObj.put("message", e.getMessage());
            response.getWriter().println(message_jsonObj);e.printStackTrace();
        } catch (SQLException e) {
            message_jsonObj.put("message","数据库操作异常");
            response.getWriter().println(message_jsonObj);
            e.printStackTrace();
        } catch (Exception e){
            message_jsonObj.put("message", "网络异常");
            response.getWriter().println(message_jsonObj);
            e.printStackTrace();
        }
    }
}